package com.sun.dream.fish.controller;

import com.sun.dream.fish.service.TRoleService;
import com.sun.dream.fish.util.ResponseUtil;
import com.sun.dream.fish.vo.PageResultVO;
import com.sun.dream.fish.vo.ResultVO;
import com.sun.dream.fish.vo.back.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljl
 * @since 2023-11-27
 */
@RestController
@RequestMapping("/role")
public class TRoleController {

    @Autowired
    TRoleService roleService;

    @PostMapping("/add")
    public ResultVO addRole(@RequestBody RoleVO roleVO) {
        return roleService.saveRole(roleVO);
    }

    @GetMapping("/list")
    public PageResultVO<RoleVO> getPage(@RequestParam(value = "name", required = false) String name,
                                        @RequestParam(value = "status", required = false) String status,
                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return roleService.getRoleList(name, status, pageNum, pageSize);
    }

    @PutMapping("/updateById")
    public ResultVO update(@RequestBody RoleVO roleVO) {
        return roleService.updateRole(roleVO);
    }

    @DeleteMapping("/deleteById")
    public ResultVO delete(@RequestParam("id") Integer id) {
        return roleService.deleteRole(id);
    }

}
